﻿@inherits BaseEditForm<Quartz_TaskDTO>

<Form @ref="_form" Model="@Data"
      LabelCol="new ColLayoutParam { Span = 8 }"
      WrapperCol="new ColLayoutParam { Span = 16 }">
    <FormItem Label="作业名称">
        <Input @bind-Value="@context.TaskName" AutoComplete=false />
    </FormItem>
    <FormItem Label="分组">
        <Input @bind-Value="@context.GroupName" AutoComplete=false />
    </FormItem>
    <FormItem Label="启用">
        <Switch @bind-Value="@context.IsEnabled" />
    </FormItem>
    <FormItem Label="Cron">
        <Input @bind-Value="@context.Cron" AutoComplete=false />
    </FormItem>
    <FormItem Label="任务类名">
        <SimpleSelect 
                @bind-Value="@context.ActionClass"
                AllowClear
                DataSource="@JobOptions"
                Placeholder="请选择类名">
        </SimpleSelect>
    </FormItem>   
    <FormItem Label="描述">
        <Input @bind-Value="@context.Remark" AutoComplete=false />
    </FormItem>
    <FormItem Label="请求方式">
        <Input @bind-Value="@context.RequestType" AutoComplete=false />
    </FormItem>
    <FormItem Label="请求地址">
        <Input @bind-Value="@context.ApiUrl" AutoComplete=false />
    </FormItem>
    <FormItem Label="密匙名">
        <Input @bind-Value="@context.AuthKey" AutoComplete=false />
    </FormItem>
    <FormItem Label="密匙值">
        <Input @bind-Value="@context.AuthValue" AutoComplete=false />
    </FormItem>
 
</Form>

@code {

    public EditForm()
    {
        Area = "Quartz_Manage";
    }

    protected override async Task OnInitializedAsync()
    {
        using (var waitfor = WaitFor.GetWaitFor(this))
        {
            await GetJobOptions();
            await base.OnInitializedAsync();
        }
    }

    private  List<string> JobOptions { get; set; }

    protected async Task GetJobOptions()
    {
        try
        {
            var result = await DataProvider.PostData<List<string>>($"/Quartz_Manage/Quartz_Task/GetJobOptions");
            if (!result.Success)
            {
                throw new Exception(result.Msg);
            }
            JobOptions = result.Data;
        }
        catch (Exception ex)
        {
            await MessageService.Error(ex.Message);
        }
    }
}